<?php

/**
 * @author aisyah
 * @copyright 2012
 */

require_once "../dao/blog_dao.php";
session_start();

require_once "../dao/database.php";
$class_db=new Database;
$modul=$_GET['modul'];
$id=$_GET['id'];

switch($modul){
    
    case "tambah":
    
        $blog = new Blog_Dao($class_db);
        
        $title = $_POST['title'];
        $content= $_POST['content'];
        $dir_file = $_FILES['image']['tmp_name'];
        $date = date('Y-m-d');
        $contributor = "harus make session";
        
        $value = "'".$date."',
                        '".$title."',
                        '".$content."',
                        '".$dir_file."',
                        '".$contributor."'";
        $row = "date,
                        title,
                        content,
                        image,
                        contributor";
        
        //masih membutuhkan class upload n session user
        $result = $blog->db->add('blog',$value, $row);
         
        //belum menampilkan pesan kesalahan
        if($result){
            location('header:blog_view.php');
        }else{
            location('header:blog_view.php?modul=tambah');
        }
        
    
    break;
    
    case "tambah_comment":
    
        require_once "../dao/comment_dao.php";
    
        $comment = new Comment_Dao($class_db);       
        
        $blog_id = $_POST['id'];
        $tgl = date('Y-m-d');
        $name= $_POST['name'];
        $email= $_POST['email'];
        $komentar= $_POST['comment'];
        
        $value = array($blog_id,"$tgl","$name","$email","$komentar");
                        
        //print_r($value);
        
        $row = 'blog_id,
                        date,
                        name,
                        email,
                        comment';
        
        if(!empty($_POST['kode'])){
            
            if($_POST['kode']==$_SESSION['captcha_session']){
                
                $result = $comment->db->add('comment',$value, $row);
                
                if($result){
                    header('location:blog_view.php?modul=tampil&id='.$blog_id);
                }
                
            }else{
                
                echo "Kode yang anda masukkan tidak cocok </br>
                    <a href=javascript:history.go(-1)<b>Ulangi lagi</b></a>";
            }
            
            
        }else{
            echo "Anda belum memasukkan kode</br>
                    <a href=javascript:history.go(-1)<b>Ulangi lagi</b></a>";
        }  
        
        
    
    break;
    
    }

?>